package com.flst.xlbibliotheque.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

import com.flst.xlbibliotheque.api.Author;
import com.flst.xlbibliotheque.api.Book;


@NamedQueries({
        @NamedQuery(name = "ALL_BOOK", query = "FROM Book ORDER BY name DESC"),
        @NamedQuery(name = "BOOK_BY_NAME", query = "FROM Book WHERE name = :name")
})
@Entity(name = "Book")
public class BookImpl implements Book{

        public static final String ALL_BOOK = "ALL_BOOK";
        public static final String BOOK_BY_NAME = "BOOK_BY_NAME";

        @Id
        @GeneratedValue(strategy = GenerationType.SEQUENCE)
        private Long id;
        
        private String name;
        private String adresse;
        
        public String getAdresse() {
			return adresse;
		}

		public void setAdresse(String adresse) {
			this.adresse = adresse;
		}


		@ManyToMany(mappedBy="booksByAuthor")
        private List<AuthorImpl> authors = new ArrayList<AuthorImpl>();
        
        public BookImpl(){
                
        }
        
        public BookImpl(String name) {
                this.name = name;
        }


        @Override
        public String getName() {
                return name;
        }

        @Override
        public List<? extends Author> getAuthors() {
                return authors;
        }

        @Override
        public int hashCode() {
                return getName().hashCode();
        }

        @Override
        public boolean equals(Object obj) {

        if (!(obj instanceof Book)){
                return false;
        }
        return ((Book) obj).getName().equals(getName());
        
        }

        public Long getId() {
                return id;
        }


		@Override
		public boolean contains(Book book) {
			// TODO Auto-generated method stub
			return false;
		}
}

        
        
        